package Iterator;

import java.util.Iterator;
public class DinerMenu implements Menu{
    static  final  int MAX_ITEMS = 6;
    int position = 0;
    MenuItem[] list;


    public DinerMenu() {
        list = new MenuItem[MAX_ITEMS];
        addItem("Vegin","asdafsdaf",true,2.99);
        addItem("Vegi2n","asdaf4sdaf",true,23.99);
        addItem("V23egin","asdafs34daf",true,24.99);
        addItem("Vegi43n","asdafs34daf",true,2.12);
        addItem("Veg34in","asdaf34sdaf",true,25.99);
    }

    public void addItem(String name, String description, boolean vegetarian, double price) {
        MenuItem menuItem = new MenuItem(name, description, vegetarian, price);
        if (position >= MAX_ITEMS) {
            System.err.println("Sorry full");
        } else {
            list[position] = menuItem;
            position = position + 1;
        }
    }

    public Iterator createIterator() {
        return new DinerMenuIterator(list);
    }

    public void remove() {
        if(position<=0){
            throw new IllegalStateException("cant remove");
        }
        if (list[position - 1] != null) {
            for (int i = position - 1; i < (list.length - 1); i++) {
                list[i] = list[i + 1];
            }
            list[list.length - 1] = null;
        }
    }

  /*  public  MenuItem[] getMenuItem() {
        return list;
    }*/
}
